package gamedemo.geom;

import org.newdawn.slick.geom.Vector2f;

public class Vector3f {

	public float x;
	public float y;
	public float z;
	
	public Vector3f() {
		this(0,0,0);
	}
	
	public Vector3f(float x, float y, float z) {
		this.x = x;
		this.y = y;
		this.z = z;
	}
	
	public Vector3f(Vector3f copy) {
		this.x = copy.x;
		this.y = copy.y;
		this.z = copy.z;
	}
	
	public Vector3f add(Vector3f other) {
		return add(other.x, other.y, other.z);
	}
	
	public Vector3f add(float x, float y, float z) {
		this.x += x;
		this.y += y;
		this.z += z;
		
		return this;
	}
	
	public Vector3f copy() {
		return new Vector3f(this.x, this.y, this.z);
	}
	
	/**
	 * Skrivet som avbildningsmatris:
	 * A(x1, y1, z1) = (x2, y2)
	 * A = [1  0  0.2
	 * 		0  1 -0.4]
	 */
	public Vector2f get2DTransformation() {
		return new Vector2f(x + z / 5, y - z / 2.5f);
	}
	
	public Vector2f get2DShadowTransformation(float ground, float imageHeight, float shadowScale) {
		float offset = ground - imageHeight;
		return new Vector2f(x + z * shadowScale / (shadowScale * 5), y - z * shadowScale / (shadowScale * 2.5f) - (y - offset) * (1 - shadowScale));
	}
}
